package com.example.cart_system.mapper;

import com.example.cart_system.pojo.Cart;
import com.example.cart_system.pojo.GoodsInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    //判断该用户是否添加了该商品到购物车
    @Select("select gid from cart where usrid = #{usrid} and gid = #{gid}")
    public String getCartId(String gid, String usrid);
    //若没添加则添加进去
    @Insert("insert into cart (gid, usrid) values (#{gid}, #{usrid})")
    public void addCart(Cart cart);
    //若添加了,则让数量加一
    @Update("update cart set cnn = cnn + 1 where gid = #{gid} and usrid = #{usrid}")
    public void addCnn(Cart cart);
    //减少数量
    @Update("update cart set cnn = cnn - 1 where gid = #{gid} and usrid = #{usrid}")
    public void reduceCnn(Cart cart);
    //显示购物车列表
    @Select("SELECT goods.gid, goods.gname, goods.gimage, goods.gprice, cart.cnn from goods, cart where goods.gid = cart.gid and usrid = #{usrid}")
    public List<GoodsInfo> getCartList(String usrid);
    //从购物车删除商品
    @Delete("delete from cart where gid = #{gid} and usrid = #{usrid}")
    public void removeCart(String gid, String usrid);
    //清空购物车
    @Delete("delete from cart where usrid = #{usrid}")
    public void deleteCart(String usrid);
}
